package com.testing.sunnycommon.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.testing.sunnycommon.mapper.SunnyCaseMapper;
import com.testing.sunnycommon.model.SunnyCase;
import com.testing.sunnycommon.service.SunnyCaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Classname SunnyCaseServiceImpl
 * @Description 类型说明
 * @Date 2023/2/22 22:11
 * @Created by 特斯汀Roy
 */
@Service("sunnyCaseService")
public class SunnyCaseServiceImpl extends ServiceImpl<SunnyCaseMapper, SunnyCase> implements SunnyCaseService {
    @Autowired
    SunnyCaseMapper sunnyCaseMapper;


    @Override
    public int deleteCases(List<Long> ids) {
        int delCount = 0;
        for (Long id : ids) {
            delCount += sunnyCaseMapper.deleteCase(id);
        }
        System.out.println("删除了" + delCount + "条用例");
        return delCount;
    }

    @Override
    public List<SunnyCase> getCasesInModule(Long moduleId) {
        return sunnyCaseMapper.getCasesInModule(moduleId);
    }

    /**
     * select * from sunny_case where module_id=13 and parent_id is null ORDER BY sort_id
     *  查询所有的用例
     * @param moduleId  模块id
     * @return
     */
    @Override
    public List<SunnyCase> listCasesInOrder(Long moduleId) {
        return list(new LambdaQueryWrapper<SunnyCase>()
                .eq(SunnyCase::getModuleId, moduleId)
                .isNull(SunnyCase::getParentId)
                .orderByAsc(SunnyCase::getSortId)
        );
    }

    /**
     * select * from sunny_case where module_id=4 and parent_id =116 ORDER BY sort_id
     * @param moduleId  其实可以不要，只是单纯为了加强条件，避免出现一些脏数据
     * @param parentId  用例记录的id编号。
     * @return
     */
    @Override
    public List<SunnyCase> listStepsInOrder(Long moduleId, Long parentId) {
        return list(new LambdaQueryWrapper<SunnyCase>()
                .eq(SunnyCase::getModuleId, moduleId)
                .eq(SunnyCase::getParentId, parentId)
                .orderByAsc(SunnyCase::getSortId)
        );
    }
}
